package com.wyx.springbootkafkaconsumerone.listener;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

@Component
public class ConsumerListener {

    @KafkaListener(
        topics = "${kafka.topic.test-topic}",
        errorHandler = "dlqErrorHandler",
        concurrency = "1"
    )
    public void onMsg(ConsumerRecord<?, ?> record, Acknowledgment ack) throws Exception {
        System.out.println("Kafka消费者接受到消息 " + record.toString());
        int i = Integer.parseInt(record.value().toString());
        Thread.sleep(1000 * 3);
        if (i > 100) {
            System.out.println(1/0);
        }
        ack.acknowledge();
    }

}
